<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
</head>
<body>
<div></div>
<div id="t1">
    <div id="t2"></div>
    <div></div>
    <div></div>
</div>
<script>
    test(() => {
        var s = document.createElement("style");
        s.textContent = "div ~ div > :nth-child(even) { background-color: red }";
        var head = document.querySelector("head");
        head.appendChild(s);
        t2.offsetTop;
        head.removeChild(s);
        t2.offsetTop;

        t1.insertBefore(document.createElement("div"), t2);
        assert_equals(internals.updateStyleAndReturnAffectedElementCount(), 1);
    }, "Removed style rules should not cause invalidation");
</script>
<body>
</html>
